package com.weigang.webservice.controller;

import com.weigang.webservice.dto.User;
import org.springframework.web.bind.annotation.*;

import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;

@RestController
@RequestMapping({"test"})
public class TestController {


    @GetMapping({"getStr1"})
    public String getStr1(@RequestParam("str") String str) {
        return "您输入的参数：" + str;
    }

    @GetMapping({"getStr2"})
    public String getStr2(@RequestParam String str) {
        return "===========》 " + str;
    }


    @GetMapping({"getStrUser"})
    public User getStrUser(@RequestParam("str") String str) {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("YYYY-MM-dd HH:mm:ss");
        System.out.println(simpleDateFormat.format(new Date()) + "====>" + str);
        List<User> list = new ArrayList();
        User user1 = new User("1", "张三", "21");
        User user2 = new User("2", "李四", "22");
        list.add(user1);
        list.add(user2);
        List<String> idList = list.stream().map(User::getId).collect(Collectors.toList());
        Map<String, User> map = new HashMap<>();
        list.stream().filter(user -> map.put(user.getId(), user) != null).forEach(user -> {
            throw new IllegalStateException("Duplicate key");
        });
        return idList.contains(str) ? map.get(str) : new User(str, str, "222");
    }
}

